package test;
import lib.db_properties_path.*;
import java.sql.*;
import java.util.*;
import lib.dbTool.*;


public class MEDICINERECORD extends DBconnection2 {
public MEDICINERECORD(SetPath set){
super(set);
}
public MEDICINERECORD(){
super(new DefaultSetPath());
}
/** Auto Increasment */
/** Primary Key */
/** int identity ; java.lang.Integer */private int idmedicinerecord;
/** bigint ; java.lang.Long */private long setmedicinetime;
/** bigint ; java.lang.Long */private long responemedicinetime;
/** int ; java.lang.Integer */private int idoldman;
public int getIdmedicinerecord(){
return  idmedicinerecord;
}
public void setIdmedicinerecord(int idmedicinerecord){
this.idmedicinerecord= idmedicinerecord;
}

public long getSetmedicinetime(){
return  setmedicinetime;
}
public void setSetmedicinetime(long setmedicinetime){
this.setmedicinetime= setmedicinetime;
}

public long getResponemedicinetime(){
return  responemedicinetime;
}
public void setResponemedicinetime(long responemedicinetime){
this.responemedicinetime= responemedicinetime;
}

public int getIdoldman(){
return  idoldman;
}
public void setIdoldman(int idoldman){
this.idoldman= idoldman;
}

public interface fn{
String TABLE_NAME = "MEDICINERECORD";
String PK = "idmedicinerecord";
String idmedicinerecord="idmedicinerecord";
String setmedicinetime="setmedicinetime";
String responemedicinetime="responemedicinetime";
String idoldman="idoldman";
}
public String sql(String SQL){
return Utility.getSQL組合字(SQL, MEDICINERECORD.fn.class);
}
public int clear() {
String SQL = "delete from MEDICINERECORD";
Object parameter[] = {};
return super.excuteUpdate(SQL, parameter);
}

public int delete(int idmedicinerecord) {
String SQL = "delete from MEDICINERECORD where idmedicinerecord=?";
Object parameter[] = {idmedicinerecord};
return super.excuteUpdate(SQL, parameter);
}

public int update(long setmedicinetime,long responemedicinetime,int idoldman, int idmedicinerecord){
String SQL = "update MEDICINERECORD set setmedicinetime=?,responemedicinetime=?,idoldman=? where idmedicinerecord=?";
Object parameter[] = {setmedicinetime,responemedicinetime,idoldman,idmedicinerecord};
return super.excuteUpdate(SQL,parameter);
}

public int insert(long setmedicinetime,long responemedicinetime,int idoldman){
String SQL = "insert into MEDICINERECORD(setmedicinetime,responemedicinetime,idoldman) values(?,?,?)";
Object parameter[] = { setmedicinetime,responemedicinetime,idoldman};
return super.excuteUpdate(SQL ,parameter);
}

public String[][] select() {
String SQL = "select * from MEDICINERECORD";
Object parameter[] = {};
return super.select(SQL, parameter);
}

public MEDICINERECORD[] select_Object() {
String SQL = "select * from MEDICINERECORD";
Object parameter[] = {};
String data[][] = super.select(SQL, parameter);MEDICINERECORD obj[] = toObject(data);return obj;}

public String[][] select( int idmedicinerecord) {
String SQL = "select * from MEDICINERECORD where idmedicinerecord=?";
Object parameter[] = {idmedicinerecord};
return super.select(SQL, parameter);}

public MEDICINERECORD[] select_Object( int idmedicinerecord) {
String data[][] = this.select(idmedicinerecord);MEDICINERECORD obj[] = toObject(data);return obj;}

public int selectCount() {
String SQL = "select count(idmedicinerecord) from MEDICINERECORD";
Object parameter[] = {};
String d[][] = super.select(SQL, parameter);
return Integer.parseInt(d[0][0]);}

public String[][] selectPage(int pageSize, int pageIndex, int rowCount) {
int desc = PaggingSQL.ASC;PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPage(pageSize, pageIndex, TABLE_NAME, PK, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount) {
PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
 /**
 * 關鍵字 where 不用寫
 * @param pageSize
 * @param pageIndex
 * @param sortName
 * @param desc
 * @param rowCount
 * @param whereCondition = 【pk>0】, 關鍵字 where 不用寫
 * @return
 */
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount, String whereCondition) {
PaggingSQL ps = new lib.dbTool.MsSQL2012();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;
//範例,關鍵字 where 不用寫, ex:【pk>0】
String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount, whereCondition);Object parameter[] = {};
return super.select(SQL, parameter);
}
public MEDICINERECORD[] selectPage_Object(int pageSize, int pageIndex, int rowCount) {
	String data[][] = this.selectPage(pageSize, pageIndex, rowCount);
	MEDICINERECORD obj[] = toObject(data);
	return obj;
}
 /**
 * 分組統計筆數
 * @param fk_List
 * @return
 */
public Map<Integer, Integer> getGroupCount(String fkName, LinkedList<Integer> fk_List){String q = "";
Object parameter[] = new Object[fk_List.size()];
int i=0;
for (Integer no : fk_List) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();String SQL = "";SQL += "SELECT "+ fkName +", count("+ fkName +") ";SQL += "FROM "+ fn.TABLE_NAME +" where "+fkName+" in (" + q + ")";SQL += "group by "+ fkName +";";String data[][] = super.select(SQL, parameter);for (int j = 0; j < data.length; j++) {int key = Integer.parseInt(data[j][0]);int count = Integer.parseInt(data[j][1]);map.put(key, count);}return map;} /**
 * Where PK in(?,?,?....)
 * @param idList
 * @return
 */
public Map<Integer, MEDICINERECORD> selectMap(LinkedList<Integer> idList){
String q = "";
Object parameter[] = new Object[idList.size()];
int i=0;
for (Integer no : idList) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, MEDICINERECORD> map = new HashMap<Integer, MEDICINERECORD>();

String SQL = "select * from MEDICINERECORD where idmedicinerecord in ("+ q +")";
String data[][] = super.select(SQL, parameter);
MEDICINERECORD[] obj = this.toObject(data);
for (MEDICINERECORD o : obj) {
map.put(new Integer(o.idmedicinerecord) , o);
}
return map;
}
public MEDICINERECORD[] toObject(String data[][]){
MEDICINERECORD[] obj = new MEDICINERECORD[data.length];
for (int i = 0; i < obj.length; i++) {
obj[i] = new MEDICINERECORD(super.getSetting());obj[i].idmedicinerecord=Integer.parseInt(data[i][0]);
obj[i].setmedicinetime=Long.parseLong(data[i][1]);
obj[i].responemedicinetime=Long.parseLong(data[i][2]);
obj[i].idoldman=Integer.parseInt(data[i][3]);
}
return obj;}
}